package cn.whit.blog.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.whit.blog.util.PageModel;
import cn.whit.blog.util.SolrUtil;

public class SearchServlet extends BaseServlet{

	private static final long serialVersionUID = 6329015123941671509L;
	
	
	
	//查询索引库，返回查询结果数据
	public String search(HttpServletRequest request, HttpServletResponse response) throws SQLException, IOException {
		String searchText = request.getParameter("searchText");
		System.out.println("searchText="+searchText);
		request.setAttribute("searchText", searchText);
		try {
			Map<String, Object> searchList = SolrUtil.search(searchText, 1L, 100L);
			List objectList = (List) searchList.get("dataList");
			PageModel pm  =  new PageModel();//  new PageModel(currentPageNum, totalRecords, pageSize);//tblogService.findByPageAndQuery(curNum,  pageSize,  query);
			//数据结果集合
			pm.setList(objectList);
			System.out.println(objectList.size());
			//总数据个数
//			pm.setTotalRecords(totalRecords);
			//总共多少页totalPageNum
//			pm.setTotalPageNum(totalPageNum);
			//当前第几页currentPageNum
//			pm.setCurrentPageNum(currentPageNum);
			
			pm.setUrl("TblogServlet?method=index");
			request.setAttribute("page", pm);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return "/view/search/list.jsp";
	}
	
}
